package com.songcha.module_mine.ui.fragment.setting.about_us

import android.os.Bundle
import android.view.View
import android.widget.ImageView
import android.widget.TextView
import com.songcha.library_base.base.BaseFragment
import com.songcha.library_business.proxy.configuration.SystemConfigurationManager
import com.songcha.library_business.util.BusinessJumpUtil
import com.songcha.library_common.ui.dialog.CustomDialog
import com.songcha.library_common.util.ClipboardUtil
import com.songcha.library_common.util.DeviceUtil
import com.songcha.library_common.util.PackageUtil
import com.songcha.library_common.util.ToastUtil
import com.songcha.module_mine.R
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.schedulers.Schedulers

class AboutUsFragment:BaseFragment() {
    init{
        TAG=AboutUsFragment::class.java.simpleName
    }

    companion object{
        const val CLICK_INTERVAL = 1000
    }

    private var mLastClickTime = 0L
    private var mContinuousClickCount = 0

    override fun getLayoutId(): Int {
        return R.layout.mine_fragment_about_us
    }

    override fun initView(savedInstanceState: Bundle?) {
        super.initView(savedInstanceState)
        if(mRootView==null) return
        mRootView!!.findViewById<TextView>(R.id.mine_tv_current_version).apply {
            text="当前版本："+PackageUtil.getPackageVersionName(context)
        }

        mRootView!!.findViewById<TextView>(R.id.mine_tv_appName).apply {
            text=PackageUtil.getAppName(context)
        }

        mRootView!!.findViewById<TextView>(R.id.mine_tv_user_protocol).setOnClickListener {
            BusinessJumpUtil.toUserPrivacyActivity(requireContext(),1)
        }

        mRootView!!.findViewById<TextView>(R.id.mine_tv_privacy_policy).setOnClickListener {
            BusinessJumpUtil.toUserPrivacyActivity(requireContext(),2)
        }

        mRootView!!.findViewById<ImageView>(R.id.mine_iv_logo).setOnClickListener {
            onClickLogo()
        }
    }
    private fun onClickLogo(){
        if(System.currentTimeMillis() - mLastClickTime <= CLICK_INTERVAL){
            mContinuousClickCount++
        }else{
            mContinuousClickCount = 1
        }

        if(mContinuousClickCount >= 5){
            mContinuousClickCount = 0
            CustomDialog.Companion.Builder(requireContext())
                .setDialogTitle("版本信息")
                .setDialogMsg(
                    "应用包名：" + PackageUtil.getPackageName(requireContext())
                        + "\n应用名称：" + PackageUtil.getAppName(requireContext())
                        + "\n渠道名称：" + PackageUtil.getUmengChannelName(requireContext())
                        + "\n版本号：" + PackageUtil.getPackageVersionName(requireContext())
                        + "\n设备号：" + DeviceUtil.getAndroidId(requireContext())
                )
                .setMsgTextAlign(View.TEXT_ALIGNMENT_TEXT_START)
                .setCancelText("取消")
                .setConfirmText("复制设备号")
                .setOnConfirmListener {
                    ClipboardUtil.copyText(requireContext(), DeviceUtil.getAndroidId(requireContext()))
                    ToastUtil.show("已复制设备号")
                    true
                }
                .create().show()
        }

        mLastClickTime = System.currentTimeMillis()
    }

}